

#THIS FILE CREATES GRAPH D1. LOAD THE COEFFICIENTS FROM EACH OF THE MODELS, WHICH ARE COPIED HERE
margins<-read.csv("./Replication Data Upload/approval_change_v1_102221.csv")

margins$coef<-as.numeric(margins$coef)
margins$se<-as.numeric(margins$se)
margins$Time.diff<-as.character(margins$Time.diff)
margins$UL<-margins$coef+(1.96*margins$se)
margins$LL<-margins$coef-(1.96*margins$se)
margins.ols<-subset(margins, test=="ols")
margins.placebo<-subset(margins, test=="placebo")

library(ggplot2)
library(gridExtra)



ols.graph<-
qplot(x    = Time.diff ,
      y    = coef,
      data = margins.ols) + 
  theme(
    #axis.text.x=element_blank(),
    axis.ticks.x=element_blank())+xlab("Number of Days From Failed Motion to Poll")+ylab("Coefficient")+
  geom_errorbar(aes(
    ymin  = LL,
    ymax  = UL,
    width = 0.15))+ theme_bw()+
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.line = element_line(colour = "black"))+
  theme(axis.line.x = element_line(color="black", size = .5),
        axis.line.y = element_line(color="black", size = .5))+
  geom_hline(yintercept=0, linetype="dashed")+ggtitle("Regression Results")+theme(plot.title = element_text(hjust = 0.5))
ols.graph

placebo.graph<-
  qplot(x    = Time.diff ,
        y    = coef,
        data = margins.placebo) + 
  theme(
    #axis.text.x=element_blank(),
    axis.ticks.x=element_blank())+xlab("Number of Days From Poll Before Failed Motion")+ylab("Coefficient")+
  geom_errorbar(aes(
    ymin  = LL,
    ymax  = UL,
    width = 0.15))+ theme_bw()+
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        axis.line = element_line(colour = "black"))+
  theme(axis.line.x = element_line(color="black", size = .5),
        axis.line.y = element_line(color="black", size = .5))+
  geom_hline(yintercept=0, linetype="dashed")+ggtitle("Placebo Results")+theme(plot.title = element_text(hjust = 0.5))
placebo.graph


grid.arrange(ols.graph, placebo.graph, ncol=2)
